package es.uji.viselab.benchmark;

import es.uji.viselab.benchmark.database.DBConnection;
import es.uji.viselab.experiment.ExperimentInterface;
import es.uji.viselab.experiment.ExperimentListener;
import es.uji.viselab.experiment.ExperimentParameters;
import es.uji.viselab.image.source.ImageListener;
import es.uji.viselab.image.source.ImageSource;
import es.uji.viselab.math.Matrix4;
import es.uji.viselab.math.Vector3;
import es.uji.viselab.robot.Robot;
import es.uji.viselab.robot.RobotListener;
import es.uji.viselab.visualservoing.VisualServoingListener;
import es.uji.viselab.visualservoing.VisualServoingTask;

public class BenchMarkingRecorder implements ImageListener, ExperimentListener, VisualServoingListener,RobotListener {
	
	private DBConnection database;

	public void setDatabase(DBConnection database) {
		this.database = database;
	}
	
	@Override
	public void cameraFeaturePointsChanged(ImageSource i) {
	}
	
	@Override
	public void robotPositionChanged(Robot robot) {
		Matrix4 pose = robot.getPoseM();
		Vector3 eep =  pose.getEndEffectorPose();
		DataPackage dp= new DataPackage(DataType.XYZ_END_EFFECTOR, eep.x, eep.y,eep.z);
		database.insert(dp);
	}

	
	@Override
	public void robotConnected(Robot robot) {
	}

	
	
	@Override
	public void newPositionRequested(VisualServoingTask vst) {
		double error =vst.getError();
		DataPackage dp= new DataPackage(DataType.ERROR, error);
		database.insert(dp);
	}
	
	@Override
	public void experimentStart(ExperimentInterface ei) {
		ExperimentParameters ep = ei.getExperimentParameters();
		int e = ep.getExperimentId();
		int g =  ep.getGroupId();
		DataPackage dp= new DataPackage(DataType.HEADER, e,g,ExperimentParameters.experimentParametersToString(ep));
		database.setNewExperimentId(e);
		database.setNewGroupId(g);
		database.insert(dp);
	}
	
	
}
